{extend name='base' /}
{block name='content'}
<body>
<div class="x-body">
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">后台管理</a>
        <a href="">系统管理</a>
        <a>
          <cite>系统设置</cite></a>
      </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
           href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
        <form class="layui-form layui-row" id="AddData">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red"></span>网站标题
                </label>
                <div class=" layui-col-md8">
                    <input type="text" name="title" required="" lay-verify="required" autocomplete="off" value="{$configData['title']?$configData.title:'';}"
                           class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red" ></span>网站标题前台显示标题
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red"></span>头部图标
                </label>
                <div class=" layui-col-md7"  style="position: relative">
                    <input type="text" name="ico" required="" lay-verify="required" autocomplete="off" value="{$configData['ico']?$configData.ico:'';}" class="layui-input" id="ico">
                    <div class="layui-upload-list" style="position:relative;left: 0px;">
                        <img class="layui-upload-img" id="demo1" width="100px" height="100px" title="头部图标预览" style="border: 1px solid #CCCCCC" src="{$configData['ico']?$configData.ico:'';}">
                        <p id="demoText"></p>
                    </div>

                </div>

                <div class="layui-col-md1">
                    <button type="button" class="layui-btn" id="test1">上传图片</button>
                </div>

                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red" ></span>网站头部logo图标
                </div>

            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label"><span class="x-red"></span>网站关键词</label>
                <div class="layui-col-md8">
                    <textarea name="keywords" class="layui-textarea">{$configData.keywords?$configData.keywords:'';}</textarea>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red"></span>请输入网站关键词
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label"><span class="x-red"></span>网站描述</label>
                <div class="layui-col-md8">
                    <textarea name="describe"  class="layui-textarea">{$configData.describe?$configData.describe:'';}</textarea>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red"></span>请输入网站描述内容
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label ">
                    <span class="x-red"></span>网站备案号
                </label>
                <div class="layui-col-md8">
                    <input type="text" name="icp" required="" lay-verify="required" autocomplete="off" value="{$configData.icp?$configData.icp:'';}"
                           class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red"></span>请输入网站备案号
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label"><span class="x-red"></span>底部内容</label>
                <div class="layui-col-md8">
                    <textarea name="btm"  class="layui-textarea">{$configData.btm?$configData.btm:'';}</textarea>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red"></span>请输入网站底部内容
                </div>
            </div>
            <input type="hidden" name="name" value="adminconfig">
            <div class="layui-form-item">
                <label  class="layui-form-label">
                </label>
                <a class="layui-btn" href="javascript:Add();">
                    保存
                </a>
            </div>
        </form>

    </div>

</div>
<script>
    function Add() {
        $.ajax({
            url: "{:url('webconfig/webConfigAdd')}",
            type: 'post',
            dataType: 'json',
            data: $('#AddData').serialize(),
            success: function (res) {
                if (res.code == 1) {
                    layer.msg(res.message, {icon: 6});
                    setTimeout(function () {

                        window.location.reload();
                    }, 1000)
                } else {
                    layer.msg(res.message, {icon: 2, time: 1000})
                }
            },
            error: function () {
                layer.msg('出错了，请稍后再试！', {icon: 5, time: 1000})
            }
        })
    }

    layui.use('upload', function() {
        var $ = layui.jquery
            , upload = layui.upload;
        var uploadInst = upload.render({
            elem: '#test1',
            exts:'ico'
            ,url: "{:url('webconfig/uploadImg')}"
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code >0){
                    layer.msg(res.message, {icon: 2, time: 1000})
                }else{
                    layer.msg(res.message, {icon: 6});
                    $('#ico').val(res.url)
                    var demoText = $('#demoText');
                    demoText.html('');
                }
                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
    })
</script>
</body>
{/block}